from rest_framework import serializers

from goods.models import Brand


class GoodsBrandsSerializer(serializers.ModelSerializer):
    class Meta:
        model = Brand
        exclude = ('create_time', 'update_time')

    def validate_name(self, value):
        brand = Brand.objects.get(name=value['name'])
        if brand:
            raise Brand.DoesNotExist('频道已存在')
        return value
